<?php
/** Rho dispatcher.
* Used to include the controller when using mod-rewrite.
*
* @package Rho
* @subpackage Rho-app
* @author Pete
* @version 0.1
* @license http://www.opensource.org/licenses/apache2.0.php Apache License, Version 2.0.*/

/** @var string PHP file extension including dot prefix. Normally .php 
*
* You may in rare circumstances need to change this on some server setups, e.g. to .php5 */
$EXT='.php';

/** @var string Location of the the Rho core file.
* IF the rho directory is inside your document root,
* change this to 'rho/core.inc.php' */
$CORE='../rho/core.inc.php';

/* Don't need to edit below here */

$parts=explode('/', substr($_SERVER['PATH_INFO'], 1) ); # trim the leading / from PATH_INFO and split by /
$dir=''; # current directory being examined by the foreach loop
$file=''; #controller file or empty if not found

foreach($parts as $part) :
  $check=$dir.$part.$EXT;
  if(file_exists($check) ){
    $file=$check;
    break;
  }
  $dir .= $part.'/';
endforeach;

unset($dir);
unset($parts);
unset($EXT);

if($file==''){ # file not found
  /** Include the core framework file */
  include_once $CORE;
  unset($CORE);
  throw new Rho_404('Page Not Found');
  exit(4); 
}

unset($CORE);
/** Include the controller - no further action, the contoller file will call Rho::init() */
include  $file;